var t = getApp();

Page({
    data: {
        keyWord: "",
        active: 0,
        member_type: "",
        listData: [],
        owner_goods_count: "",
        vip_goods_count: "",
        goodsTotal: 1,
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        wx.setNavigationBarTitle({
            title: "会员管理"
        }), t.type && (this.setData({
            member_type: t.type
        }), this.init(), this.getData()), this.getUser(), this.setData({
            plugin_setting: wx.getStorageSync("yz_basic_info").plugin_setting.debt_shop || {}
        });
    },
    stepperTap: function(t) {
        var a = t.detail;
        this.setData({
            goodsTotal: a
        });
    },
    tapclose: function() {
        this.setData({
            RenewShow: !1
        });
    },
    blackGo: function() {
        wx.navigateBack({
            delta: 0
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {},
    fieldChange: function(t) {
        console.log(this.data.keyWord), this.init(), this.getData();
    },
    changeTap: function(t) {
        var a = t.detail.index;
        this.setData({
            active: a,
            keyWord: ""
        }), this.init(), this.getData();
    },
    renewTap: function(t) {
        var a = t.currentTarget.dataset.item.has_one_debtor.id;
        this.setData({
            RenewShow: !0,
            renewUserId: a
        });
    },
    init: function() {
        this.setData({
            isLoadMore: !0,
            page: 1,
            total_page: 0,
            listData: []
        });
    },
    getData: function() {
        var a = this, e = "";
        e = 0 == this.data.active ? t.getNetAddresss("plugin.debt-shop.frontend.debtor.ownerList") : t.getNetAddresss("plugin.debt-shop.frontend.debtor.vipList"), 
        console.log(this.data.keyWord, "aaaaaa"), t._postNetWork({
            url: e,
            data: {
                member_kwd: this.data.keyWord
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (e.data.data.forEach(function(t) {
                    t.common_credit = Number(t.common_credit), t.frozen_credit = Number(t.frozen_credit);
                }), a.data.isLoadMore = !0, a.data.total_page = e.data.last_page, a.data.total_page || (a.data.total_page = 0), 
                a.setData({
                    listData: e.data.data
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var a = this, e = "";
        this.data.isLoadMore = !1, this.data.page >= this.data.total_page || (this.data.page = this.data.page + 1, 
        e = 0 == this.data.active ? t.getNetAddresss("plugin.debt-shop.frontend.debtor.ownerList") : t.getNetAddresss("plugin.debt-shop.frontend.debtor.vipList"), 
        t._getNetWork({
            url: e,
            data: {
                page: this.data.page,
                member_kwd: this.data.keyWord
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (e.data.data.forEach(function(t) {
                    t.common_credit = Number(t.common_credit), t.frozen_credit = Number(t.frozen_credit);
                }), a.data.isLoadMore = !0, a.setData({
                    listData: e.data.data
                })) : (a.data.page = a.data.page - 1, a.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        }));
    },
    getUser: function() {
        var a = this, e = t.getNetAddresss("plugin.debt-shop.frontend.debt-member.applyData");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    owner_goods_count: e.data.debtor_goods_count,
                    owner_goods_id: e.data.debtor_goods_id,
                    vip_goods_id: e.data.vip_goods_id,
                    vip_goods_count: e.data.vip_goods_count
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    renewPost: function() {
        var a = this;
        if (this.data.goodsTotal > (0 == this.data.active ? this.data.owner_goods_count : this.data.vip_goods_count)) wx.showToast({
            icon: "none",
            title: "拥有商品数量不足",
            duration: 1500
        }); else {
            var e = {
                id: this.data.renewUserId,
                count: this.data.goodsTotal
            }, o = t.getNetAddresss("plugin.debt-shop.frontend.debt-member.rechargeDebtMemberTime");
            t._getNetWork({
                url: o,
                data: e,
                success: function(t) {
                    var e = t.data;
                    1 == e.result ? (a.setData({
                        RenewShow: !1
                    }), wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1e3,
                        success: function() {
                            this.init(), this.getData();
                        }
                    })) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    toDetail: function() {
        var t = "";
        t = 0 == this.data.active ? this.data.owner_goods_id : this.data.vip_goods_id, wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + t
        });
    }
});